let Game = require('TxGame')
let Seat = require('Seat')
let {Global} = require('Global')


cc.Class({
    extends: cc.Component,
    properties: {
        title: cc.Label,
        countLbl: cc.Label,
        count: {
            default: 0,
            visible: false
        },
        currentCommand: {
            default: 0x40,
            visible: false
        }
    },

    onLoad() {
        /*收到状态改变*/
        //this.reCount()
    },

    registerEvent(){
        window.sock.node.on("11-23", e => {
            let info = e.detail
            this.node.active = true
            if (4 === info.actionType) {
                if (!info.errorNo) {
                    this.currentCommand = info.action
                    switch (info.action) {
                        case 0x40: //发牌
                            this.reCount()
                            this.title.string = "发牌"
                            break
                        default:
                            this.countLbl.node.active = false
                            this.title.string = "关闭"
                            break
                    }
                } else {
                    console.log("操作失败")
                }
            }
        })

        window.sock.node.on("11-5", e => {
            this.node.active = false
        })

        window.sock.node.on("11-22", e => {
            this.node.active = true
        })
    },

    reCount() {
        this.unschedule(this.countDown)
        this.count = 60
        this.schedule(this.countDown, 1,)
        this.countLbl.node.active = true
    },

    countDown() {
        this.count--
        if (this.count === 0) {
            this.countLbl.node.active = false
        }
        this.countLbl.string = `${this.count}s`
    },

    action() {
        window.sock.action({actionType: 4, action: this.currentCommand})
    }

})